﻿using GoldDigger.Models;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using TPL.Xna.Common;

namespace GoldDigger.Sprites
{
    internal class ItemSprite : ImageSprite
    {
        public float Weight { get; set; }
        public int Value { get; set; }
        public ItemType Type { get; set; }

        public ItemSprite(Texture2D image)
            : base(image)
        {
            ZIndex = 0.2f;
            Origin = new Vector2(Image.Width, Image.Height) / 2;
            SpriteAreaScale = 1f;
        }

        public float SpriteAreaScale { get; set; }

        /// <summary>
        /// Call to signal this item that it is being pulled.
        /// </summary>
        public virtual void MarkAsBeingCollected()
        {
        }

        /// <summary>
        /// Add area as rectangle around the image.
        /// </summary>
        private SpriteArea _area;
        public override SpriteArea SpriteArea
        {
            get
            {
                if (_area != null) return _area;

                var normal = new Vector2(Image.Width, Image.Height) * Scale;
                var scaled = normal * SpriteAreaScale;
                var pos = normal - scaled;
                _area = new RectangleSpriteArea(Screen.ScreenManager.GraphicsDevice, pos, scaled);
                _area.Shape.Origin = normal / 2;
                return _area;
            }
        }


    }
}